package com.sgcc.ln.pmos.common.base;

import android.os.Bundle;

public abstract class MvpBaseActivity<P extends BasePresenter> extends BaseActivity implements IView {

    protected P mPresenter;

    @Override
    protected void onCreate(Bundle arg) {
        mPresenter = createPresenter();
        //presenter取得与界面的联系
        if (mPresenter != null) {
            mPresenter.attachView(this);
        }
        super.onCreate(arg);

    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        //presenter断开与界面的联系
        try {
            if (mPresenter != null) {
                mPresenter.detachView();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /**
     * 创建Presenter
     *
     * @return
     */
    protected abstract P createPresenter();


}